import { HTTP } from "../utils/http";
class ClassicModel extends HTTP {
    getLatest(callback) {
        this.request({
            url: "/classic/latest",
            success: res => {
                let index = res.index;
                callback(res);
                wx.setStorageSync("latest", index)
            }
        })
    }

    getClassic(index, NextOrPrevious, callback) {
        let inx = (NextOrPrevious == "next") ? index + 1 : index - 1;
        const classic = wx.getStorageSync(this._getKey(inx));
        if (classic) {
            callback(classic)
        } else {
            this.request({
                url: `/classic/${index}/${NextOrPrevious}`,
                success: res => {
                    callback(res);
                    wx.setStorageSync(this._getKey(res.index), res)
                }
            })
        }
    }
    isFirst(index) {
        return index == 1 ? true : false
    }
    isLatest(index) {
        const latest = wx.getStorageSync('latest');
        return index == latest ? true : false;
    }
    _getKey(index) {
        return "classic" + index;
    }

    getFavor(callback){
        this.request({
            url:"/classic/favor",
            success:res=>{
                callback(res)
            }
        })
    }
}
export { ClassicModel }